const mysql=require('mysql2/promise'),
log=console.log,
{con}=require('./common.js');

//查找文章的全部信息
async function essay(id){
    const sql = `SELECT * FROM user.essay where id='${id}'`;
    let [rows] = await con.execute(sql);
    return rows;
}

//查找对应的user的id
async function userId(id){
    const sql = `SELECT user FROM user.essay where id='${id}'`;
    let [rows] = await con.execute(sql);
    return rows;
}

//查找用户头像和名字
async function user(id){
    const sql = `SELECT username,image FROM user.user where id='${id}'`;
    let [rows] = await con.execute(sql);
    return rows;
}

//查找文章的图片
async function essayImage(id){
    const sql = `SELECT img FROM user.essayimage where id='${id}'`;
    let [rows] = await con.execute(sql);
    return rows;
}

//查找文章的评论
async function comment(id){
    const sql = `SELECT * FROM user.comment where passageId='${id}'`;
    let [rows] = await con.execute(sql);
    return rows;
}

async function likeState(userId){
    const sql = `SELECT passageId FROM user.like where userId='${userId}'`
    let [rows] = await con.execute(sql);
    return rows;
}

module.exports={essay,userId,user,essayImage,comment,likeState};